﻿package mortal.game.view.market.sale
{
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.market.*;
    import mortal.game.view.market.myQiugou.*;
    import mortal.mvc.core.*;

    public class MktSaleBase extends GSprite
    {
        protected var _bg:ScaleBitmap;
        protected var _titleBg:ScaleBitmap;
        protected var _title:GBitmap;
        protected var _itemBg:GBitmap;
        protected var _item:BaseItem;
        protected var _txtPrice:MoneyInput;
        protected var _timeBox:GComboBox;
        protected var _txtTax:MoneyItem;
        protected var _btnSale:GButton;
        protected var _btnReset:GButton;
        protected var _btnBroadcast:GCheckBox;
        protected var _txtBoradCastCost:MoneyItem;
        protected var _txtMySales:GTextFiled;

        public function MktSaleBase()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = TextFormatAlign.RIGHT;
            this._bg = UIFactory.bg(0, 0, 340, 420, this);
            this._titleBg = UIFactory.bg(1, 0, 350, 25, this, "RegionTitleBg");
            this._title = UIFactory.bitmap(ImagesConst.market2, 0, 0, this);
            this._title.x = (this._titleBg.width - this._title.width) / 2;
            this._title.y = (this._titleBg.y + this._titleBg.height - this._title.height) / 2;
            this._itemBg = UIFactory.bitmap(ImagesConst.marketItemBg, 0, 50, this);
            this._itemBg.x = (this._bg.width - this._itemBg.width) / 2;
            this._item = UIFactory.getUICompoment(BaseItem, 141, 56, this);
            this._item.setItemStyle(ItemStyleConst.Big, null, 0, 0);
            this._txtPrice = UIFactory.getUICompoment(MoneyInput, 115, 180, this);
            this._txtPrice.unit = EPriceUnit._EPriceUnitCoinBind;
            this.updateUnit();
            this._timeBox = UIFactory.gComboBox(115, 216, 70, 22, null, this);
            this._timeBox.dataProvider = MktModConfig.dpTimeType.clone();
            this._timeBox.selectedIndex = 0;
            var _loc_2:* = UIFactory.textField("保存费", this._timeBox.x + this._timeBox.width, this._timeBox.y, 41, 20, this);
            pushUIToDisposeVec(_loc_2);
            this._txtTax = UIFactory.getUICompoment(MoneyItem, _loc_2.x + _loc_2.width + 40 + 20, _loc_2.y, this);
            this._txtTax.unit = EPriceUnit._EPriceUnitCoinBind;
            var _loc_3:* = GlobalStyle.textFormatAnjin;
            pushUIToDisposeVec(UIFactory.textField("寄售数量：", 50, 144, 68, 22, this, _loc_3));
            pushUIToDisposeVec(UIFactory.textField("寄售总价：", 50, 180, 68, 22, this, _loc_3));
            pushUIToDisposeVec(UIFactory.textField("寄售时长：", 50, 216, 68, 22, this, _loc_3));
            this._btnSale = UIFactory.gButton("寄售", 112, 267, 55, 22, this);
            this._btnReset = UIFactory.gButton("重置", 188, 267, 55, 22, this);
            this._btnBroadcast = UIFactory.checkBox("世界频道宣传，花费", 86, 312, 128, 20, this);
            var _loc_4:* = Cache.instance.role.entityInfo.level;
            this._txtBoradCastCost = UIFactory.getUICompoment(MoneyItem, this._btnBroadcast.x + this._btnBroadcast.width + 35, this._btnBroadcast.y, this);
            this._txtBoradCastCost.unit = EPriceUnit._EPriceUnitCoinBind;
            this._txtBoradCastCost.value = MktModConfig.BroadcastCost;
            if (_loc_4 < GameDefConfig.instance.getSystemOpenLevel(104))
            {
                this._btnBroadcast.visible = false;
                this._txtBoradCastCost.visible = false;
            }
            this._txtMySales = UIFactory.textField("", 220, 360, 110, 28, this);
            this._txtMySales.htmlText = HTMLUtil.addColor("<u><a href=\'event:1\'>查看我的寄售物品</a></u>", GlobalStyle.colorLv);
            this._txtMySales.configEventListener(TextEvent.LINK, this.onTextLink);
            this._txtMySales.configEventListener(MouseEvent.MOUSE_OVER, this.onMouseOver);
            this._txtMySales.configEventListener(MouseEvent.MOUSE_OUT, this.onMouseOut);
            this._timeBox.configEventListener(Event.CHANGE, this.onTimeBoxChange);
            this._txtPrice.configEventListener(Event.CHANGE, this.onTxtPriceChangeHandler);
            this._btnBroadcast.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._btnReset.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._btnSale.configEventListener(MouseEvent.CLICK, this.clickHandler);
            NetDispatcher.addCmdListener(ServerCommand.MarketResultSellItem, this.sellItemBack);
            this.resetUI();
            return;
        }// end function

        protected function resetUI() : void
        {
            return;
        }// end function

        protected function reset(param1:Boolean = false) : void
        {
            this._timeBox.selectedIndex = 0;
            this._btnBroadcast.selected = false;
            this.updateTax();
            return;
        }// end function

        private function sellItemBack(param1:Object) : void
        {
            this.reset(true);
            return;
        }// end function

        protected function clickHandler(event:MouseEvent) : void
        {
            if (event.currentTarget == this._btnBroadcast)
            {
            }
            else if (event.currentTarget == this._btnReset)
            {
            }
            else if (event.currentTarget == this._btnSale)
            {
            }
            return;
        }// end function

        private function onTimeBoxChange(event:Event) : void
        {
            this.updateTax();
            return;
        }// end function

        protected function onTxtPriceChangeHandler(event:Event) : void
        {
            this.updateTax();
            return;
        }// end function

        protected function updateTax() : void
        {
            var _loc_1:* = MktModConfig.getTax(this._timeBox.selectedItem.timeType, this._txtPrice.unit, this._txtPrice.value);
            this._txtTax.value = _loc_1;
            return;
        }// end function

        protected function updateUnit() : void
        {
            if (this._txtPrice.unit == EPriceUnit._EPriceUnitCoin || this._txtPrice.unit == EPriceUnit._EPriceUnitCoinBind)
            {
                this._txtPrice.maxValue = 999999;
            }
            else if (this._txtPrice.unit == EPriceUnit._EPriceUnitGold || this._txtPrice.unit == EPriceUnit._EPriceUnitGoldBind)
            {
                this._txtPrice.maxValue = 9999;
            }
            if (this._txtPrice.value > this._txtPrice.maxValue)
            {
                this._txtPrice.value = this._txtPrice.maxValue;
            }
            return;
        }// end function

        private function setMoneyBmpPos(param1:GBitmap, param2:DisplayObject, param3:DisplayObjectContainer) : void
        {
            param1.x = param2.x + param2.width;
            param1.y = param2.y + (param2.height - param1.height) / 2;
            param3.addChild(param1);
            return;
        }// end function

        private function onTextLink(event:TextEvent) : void
        {
            MarketMySalePanel.instance.show();
            return;
        }// end function

        private function onMouseOver(event:MouseEvent) : void
        {
            CursorManager.showCursor(CursorManager.BUTTON);
            return;
        }// end function

        private function onMouseOut(event:MouseEvent) : void
        {
            CursorManager.hideFromButton();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            NetDispatcher.removeCmdListener(ServerCommand.MarketResultSellItem, this.sellItemBack);
            this._bg.dispose(param1);
            this._titleBg.dispose(param1);
            this._title.dispose(param1);
            this._itemBg.dispose(param1);
            this._item.dispose(param1);
            this._txtPrice.dispose(param1);
            this._timeBox.dispose(param1);
            this._txtTax.dispose(param1);
            this._btnSale.dispose(param1);
            this._btnReset.dispose(param1);
            this._btnBroadcast.dispose(param1);
            this._txtBoradCastCost.dispose(param1);
            this._txtMySales.dispose(param1);
            this._bg = null;
            this._titleBg = null;
            this._title = null;
            this._itemBg = null;
            this._item = null;
            this._txtPrice = null;
            this._timeBox = null;
            this._txtTax = null;
            this._btnSale = null;
            this._btnReset = null;
            this._btnBroadcast = null;
            this._txtBoradCastCost = null;
            this._txtMySales = null;
            return;
        }// end function

    }
}
